
{include file="public/meta" /}
    

</head>

<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>学生数据导入</h5>
                    <div class="ibox-tools">
                        <a class="link">
                            <b>
                                <i class="layui-icon layui-icon-refresh"></i>
                            </b>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <div class="layui-card-header">下载导入模版&emsp;
                        <a href="http://nxist.crukou.com/template/template.xlsx" class="layui-btn layui-btn-sm">
                            <i class="layui-icon layui-icon-download-circle"></i>
                                下载模版
                        </a>
                    </div>
                    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
                        <legend>请先根据模版内容再上传学生信息，仅支持xlsx</legend>
                    </fieldset>
                    <div class="layui-upload">
                        <button type="button" class="layui-btn layui-btn-normal" id="test8">选择文件</button>
                        <button type="button" class="layui-btn" id="test9">
                            <i class="layui-icon layui-icon-upload"></i>上传
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    layui.use('upload', function() {
        var $ = layui.jquery
            , upload = layui.upload;
        //选完文件后不自动上传
        upload.render({
            elem: '#test8'
            ,url: '{:url(\'api/upload/upload_xlsx\')}' //改成您自己的上传接口
            ,auto: false
            ,multiple: false
            ,accept: 'file'
            ,exts: 'xlsx'
            ,size: 0 //不限制大小
            ,bindAction: '#test9'
            ,done: function(res){
                if(res.status == 500) {
                    layer.open({
                        title: '文件上传'
                        ,content: res.message
                    });
                }else if(res.status == 200) {
                    layer.msg('上传成功，正在解析，请稍等.....');
                    var index = layer.load();
                    $.ajax({
                        url: "{:url('admin/student/index')}",
                        type: 'post',
                        dataType: 'json',
                        data: {msg_url: res.message,dir: res.data.dir},
                        success: function (res) {
                            if (res.data == 1) {
                                layer.close(index);
                                layer.alert(res.message, {icon: 1});
                            } else if (res.data == 0) {
                                layer.open({
                                    title: '导入失败'
                                    ,content: res.message
                                });
                            } else {
                                layer.open({
                                    title: '导入失败'
                                    ,content: '出现未知错误，如果问题一直出现，您可以联系管理员或站点留言'
                                });
                            }
                        }, error: function () {
                            layer.close(index);
                            layer.open({
                                title: '解析失败'
                                , content: '当前网络环境不安全，拒绝登录，请调整网络环境'
                            });
                        }
                    });
                }
            },error: function (res) {
                layer.open({
                    title: '文件上传'
                    ,content: '上传失败！请重新上传！'
                });
            }
        });
    });
</script>
    <!-- 全局js -->
    {include file="public/footer" /}
</body>

</html>
